//
//  NSReach+Extension.swift
//  weibo
//
//  Created by 陈经纬 on 16/7/22.
//  Copyright © 2016年 陈经纬. All rights reserved.
//

import UIKit

extension String {

    func cachesDir() -> String {
        // 1.获取缓存目录的路径
        let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        // 2.生成缓存路径
        let name = (self as NSString).lastPathComponent
        
        let filePath = (path as NSString).stringByAppendingPathComponent(name)
        return filePath
    }
    
    func documenDir() -> String {
        // 1.获取缓存目录的路径
        let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        // 2.生成缓存路径
        let name = (self as NSString).lastPathComponent
        
        let filePath = (path as NSString).stringByAppendingPathComponent(name)
        return filePath
    }
    
    func tempDir() -> String {
        // 1.获取缓存目录的路径
        let path = NSTemporaryDirectory()
        // 2.生成缓存路径
        let name = (self as NSString).lastPathComponent
        
        let filePath = (path as NSString).stringByAppendingPathComponent(name)
        return filePath
    }
}
